Ext.ux.DynamicGrid=function(config){
	var cmDataArray = new Array();

	var formFields = [{
		name : 'uniqueCode',
		xtype : 'hidden'
	}];

	for (var i = 0; i < config.gridColumns.length; i++) {
		cmDataArray[cmDataArray.length] = this.createColumn(config.gridColumns[i]);
		var formField = this.createFormField(config.gridColumns[i]);
		if (formField) {
			formFields[formFields.length] = formField;
		}
	}

	var filters = new Ext.grid.GridFilters({
		filters : config.gridColumns
	});
	
	this.config=config||new Object();
	
	this.config.cmDataArray=cmDataArray;
	this.config.formFields=formFields;
	this.config.filters=filters;
	this.config.baseParams={clazz:config.clazz};
	this.config.el='grid';
	
	/**
	Ext.Ajax.request({					// 调用Ajax发送请求到后台
			scope:this,
			url:config.url,//'../hf/gridImpl.do?action=tableInfo&uniqueCode=10066',					//删除grid数据的url.
			success:function(transport){				//处理成功后返回的函数
				var oXmlDom=transport.responseText;
				if(oXmlDom!=''){
					var content=eval("("+oXmlDom+")");
					var obj=content.data;
					var cmDataArray=new Array();
					
					var formFields=[{
						name : 'uniqueCode',
						xtype:'hidden'
					}];
					
					
					for(var i=0;i<obj.gridColumns.length;i++){
						cmDataArray[cmDataArray.length]=this.createColumn(obj.gridColumns[i]);
						var formField=this.createFormField(obj.gridColumns[i]);
						if(formField){
							formFields[formFields.length]=formField;
						}						
					}

				var filters = new Ext.grid.GridFilters({
				  filters:obj.gridColumns});
						
				new Ext.ux.GridExtend({
					baseUrl:obj.baseUrl,
					editUrl:obj.editUrl,
					deleteUrl:obj.deleteUrl,
					listUrl:obj.listUrl,
					formSaveUrl:obj.formSaveUrl,
					name:obj.name,
					baseParams:{clazz:obj.clazz},
					tbarForward:config.tbarForward,
					tbarBack:config.tbarBack,
					exportUrl:obj.exportUrl,	
					el:'grid',
					sm:new Ext.grid.CheckboxSelectionModel({//start Ext.grid.CheckboxSelectionModel
						//选择全部时，只选择私有的分类
						selectAll : function(){
					        if(this.locked) return;
					        this.selections.clear();
					        for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
					        	if(this.grid.store.data.items[i].json.isPublic!='0'){
					        		this.selectRow(i, true);
					        	}		            
					        }
					    },
					    //只属于私有的分类的行才有checkbox
					    renderer : function(v, p, record,rowIndex){
					    	if(record.json.isPublic!='0'){
					    		return '<div class="x-grid3-row-checker">&#160;</div>';
					    	}else{
					    		return ;
					    	}
					    }
					}),
					rowdblclick:function(grid, rowIndex, e){
						var selectId=this.gridStore.data.items[rowIndex].id;
						if(this.gridStore.data.items[rowIndex].json.isPublic=='0'){
							return;
						}
						this.editInfo(selectId);
					},
					formFields:formFields,
					filters:filters,
					cmDataArray:cmDataArray
				}).render();
				}else{
					this.grid.store.reload();		//重新加载grid中的数据
					this.reloadStore();
				}
			},
			failure:function(){				//处理后台删除失败的函数
				Ext.MessageBox.alert('消息','加载数据失败失败!');
			}
		});  */
}
Ext.ux.DynamicGrid.prototype={
	createColumn:function(obj){
		var oColumn=new Object();
		oColumn.header=obj.header;
		oColumn.dataIndex=obj.dataIndex;
		oColumn.sortable=obj.sortable;
		
		if(obj.type=="boolean"){
			oColumn.yesText=obj.yesText;
			oColumn.noText=obj.noText;
			
			oColumn.renderer=function(value){
							if(value==1){
								return oColumn.yesText;
							}else if(value==0){
								return oColumn.noText;
							}else{
								return ;
							}
						};
		}
		return oColumn;
	},
	/**
	 * 创建form字段
	 */
	createFormField:function(obj){
		//debugger;
		if(!obj.formField){
			return null;
		}
		
		var oField=new Object();
		
		if(obj.xtype=="radio"){
			oField=this.createRadioGroupField(obj);
		}else{
			oField.fieldLabel=obj.fieldLabel;
			oField.allowBlank=obj.allowBlank;
			oField.name=obj.dataIndex;
			oField.xtype=obj.xtype;
			oField.anchor=obj.anchor||'80%';
			if(obj.xtype=="numberfield"){
				oField.allowDecimals=obj.allowDecimals||false;
				oField.maxValue=obj.maxValue;
				oField.minValue=obj.minValue;
			}
		}
				
		return oField;
	},
	/**
	 * 创建radio
	 */
	createRadioGroupField:function(obj){
		var radioField={
		    layout:'table',
            autoHeight:true,
		    baseCls : 'x-plain',
		    items:[
		    	{
			   	 	 layout: 'form',
		             baseCls : 'x-plain',
		             cls:'x-form-field',
		             width:100,
		         	 items: [{text: obj.fieldLabel+':' ,baseCls : 'x-plain',xtype:'label'}]}
		    ]
		};
		
		var boxLabels=Ext.decode(obj.boxLabel);

		for(var i=0;i<boxLabels.length-1;i++){
			var oRadio=boxLabels[i];
			radioField.items.add({
				cls:'x-form-field',
				baseCls : 'x-plain',items: [{allowBlank:false,baseCls : 'x-plain',boxLabel:oRadio.boxLabel,inputValue:oRadio.value, name:obj.dataIndex,xtype:'radio'}]
			});
		}
		
		var oRadio=boxLabels[boxLabels.length-1];
		radioField.items.add({
			cls:'x-form-field',
			baseCls : 'x-plain',
			items: [{baseCls : 'x-plain',
				boxLabel:oRadio.boxLabel,
				inputValue:oRadio.value, 
				name:obj.dataIndex,
				invalidText:'此项为必选选项',	
				showInvalidText:true,		//在此控件后添加错误提示
				xtype:'radio'}]
		});
		
		
		return radioField;
		
	},
	//渲染grid
	render:function(){
		this.gridExtend = new Ext.ux.GridExtend(this.config);
		this.grid = this.gridExtend.grid;
		this.gridExtend.render();
	}
}